import FetchHelper from "../helper/fetch-helper";
import { useState, useEffect } from 'react'
import _ from 'lodash';
import { isIntersects, wktToGeom,geomToWkt } from "../helper/mapHelper";
export default class ZdfhApi {
    static async listByPolygon(polygon) {
        let wkt = polygon
        if (!_.isString(polygon)) {
            wkt = geomToWkt(wkt);
        }
        const resp = await FetchHelper.getJson(`/admin-api/ybyj/czt/countByXlAndWkt`, {
            wkt: wkt
        })
        resp.data = resp.data?.map(item => {
            return {
                name: item.cztxl,
                count: item.count
            }
        })
        return resp;

    }
    static async list(params) {
        try {
            const resp = await FetchHelper.getJson(`/admin-api/ybyj/cztjcb/list`, {
                //xzqhbm: window.userAreaCode,
                ...params
            })
            resp.rows = resp?.rows?.map(item => {

                if (item?.xq) {
                    try {
                        const json = JSON.parse(item?.xq);
                        return {
                            ...json,
                            ...item,
                        }
                    } catch (e) {

                    }
                }
                return item;
            })
            return resp;
        } catch (err) {
            return { rows: [] }
        }
    }
    //监测监控台站
    static async monitor(params) {
        try {
            const resp = await FetchHelper.getJson(`/admin-api/ybyj/jcd/list`, {
                ...params
            })
            resp.rows = resp?.rows?.map(item => {

                if (item?.xq) {
                    try {
                        const json = JSON.parse(item?.xq);
                        return {
                            ...json,
                            ...item,
                        }
                    } catch (e) {

                    }
                }
                return item;
            })
            return resp;
        } catch (err) {
            return { rows: [] }
        }
    }
    //致灾风险分析
    static async zzfx_fengxi(wkt){
        if(!_.isString(wkt)){
            wkt=geomToWkt(wkt);
        }
        const resp=await FetchHelper.getJson(`/admin-api/ybyj/yhsj/groupByYhLxAndWkt`,{
            wkt:wkt
        })
        return resp;
    }
}